package com.somnus.demo.androiddatabingdemo;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.somnus.demo.androiddatabingdemo.bean.BaseObServableUserBean;
import com.somnus.demo.androiddatabingdemo.bean.ObservableFieldUserBean;
import com.somnus.demo.androiddatabingdemo.databinding.ActivityBaseObservaleAtyBinding;

public class BaseObservaleAty extends AppCompatActivity {
    BaseObServableUserBean mUser;
    ObservableFieldUserBean mObservableFieldUserBean;
    ActivityBaseObservaleAtyBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_base_observale_aty);
        mUser = new BaseObServableUserBean();
        mUser.setUserName("李四");
        mUser.setUserIcon("http://img07.tooopen.com/images/20170314/tooopen_sy_201827185379.jpg");
        binding.setUser(mUser);


        mObservableFieldUserBean = new ObservableFieldUserBean();
        mObservableFieldUserBean.userName.set("张三");
        mObservableFieldUserBean.userIcon.set("http://img07.tooopen.com/images/20170314/tooopen_sy_201827185379.jpg");
        binding.setField(mObservableFieldUserBean);

        binding.setAcivity(this);


    }

    public void onClickChange(View v) {
//        mUser.setUserName("李四（改）");
//        binding.setUser(mUser);
        /***
         * 继承 BaseObservable 來改變UI
         */
        mUser.setUserName("李四（改）");
        mUser.setUserIcon("http://img07.tooopen.com/images/20170327/tooopen_sy_203416617579.jpg");
    }

    public void onClickObservableField(View v) {
//        mUser.setUserName("李四（改）");
//        binding.setUser(mUser);
        /***
         *  改變UI
         */
        mObservableFieldUserBean.userName.set("李四（改）");
        mObservableFieldUserBean.userIcon.set("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1495172760&di=b7a268992cb019b5f78d873c50501752&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.qqzhi.com%2Fupload%2Fimg_5_1211398008D2764690415_23.jpg");
    }

}
